﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace WP5DMAPP.PolarScence
{
    public sealed partial class PolarScenceSettingButton : UserControl
    {
        public event EventHandler IsSelectedChanged;

        bool isselected,pointerinside;

        public bool IsSelected
        {
            get
            {
                return isselected;
            }
            set
            {
                isselected = value;
                IsSelectedChanged?.Invoke(this, new EventArgs());
            }
        }

        public string Icon
        {
            get
            {
                return IconTextBlock?.Text;
            }
            set
            {
                if (IconTextBlock != null)
                {
                    IconTextBlock.Text = value;
                }
            }
        }


        public PolarScenceSettingButton()
        {
            this.InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (IsSelected)
            {
                VisualStateManager.GoToState(this, "Selected", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "Normal", true);
            }
        }

        private void UserControl_PointerEntered(object sender, PointerRoutedEventArgs e)
        {
            if (IsSelected)
            {
                VisualStateManager.GoToState(this, "SelectedPointOver", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "NormalPointOver", true);
            }
        }

        private void UserControl_PointerExited(object sender, PointerRoutedEventArgs e)
        {
            if (IsSelected)
            {
                VisualStateManager.GoToState(this, "Selected", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "Normal", true);
            }
        }

        private void UserControl_Tapped(object sender, TappedRoutedEventArgs e)
        {
            IsSelected = !IsSelected;
        }

        private void UserControl_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            pointerinside = true;
            if (IsSelected)
            {
                VisualStateManager.GoToState(this, "SelectedPressed", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "NormalPressed", true);
            }
        }

        private void UserControl_PointerReleased(object sender, PointerRoutedEventArgs e)
        {

            if (IsSelected)
            {
                VisualStateManager.GoToState(this, "Selected", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "Normal", true);
            }
        }
    }
}
